#include "bsp_led.h"

void BSP_Led_Init(void)
{
	stc_gpio_cfg_t stcGpioCfg;
    
    ///< 打开GPIO外设时钟门控
    Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE); 
    
    ///< 端口方向配置->输出 外部三极管驱动led,高电平点亮.
    stcGpioCfg.enDir = GpioDirOut;
    ///< 端口上下拉配置-> none
    stcGpioCfg.enPu = GpioPuDisable;
    stcGpioCfg.enPd = GpioPdEnable;
    
    Gpio_Init(EVB_LEDR_PORT, EVB_LEDR_PIN, &stcGpioCfg);
	Gpio_Init(EVB_LEDY_PORT, EVB_LEDY_PIN, &stcGpioCfg);
	Gpio_Init(EVB_LEDG_PORT, EVB_LEDG_PIN, &stcGpioCfg);
	Gpio_Init(EVB_LEDB_PORT, EVB_LEDB_PIN, &stcGpioCfg);
	
	///< LED关闭
    Gpio_ClrIO(EVB_LEDR_PORT, EVB_LEDR_PIN);
    Gpio_ClrIO(EVB_LEDY_PORT, EVB_LEDY_PIN);
	Gpio_ClrIO(EVB_LEDG_PORT, EVB_LEDG_PIN);
	Gpio_ClrIO(EVB_LEDB_PORT, EVB_LEDB_PIN);   
}


void BSP_led_blink(en_led_t LED)
{
	if(LED == LED_RED)
	{
		M0P_GPIO->PEOUT ^= ((1UL)<<(EVB_LEDR_PIN));
	}
	
	if(LED == LED_YELLOW)
	{
		M0P_GPIO->PEOUT ^= ((1UL)<<(EVB_LEDY_PIN));
	}

	if(LED == LED_BLUE)
	{
		M0P_GPIO->PEOUT ^= ((1UL)<<(EVB_LEDB_PIN));
	}
	if(LED == LED_GREEN)
	{
		M0P_GPIO->PEOUT ^= ((1UL)<<(EVB_LEDG_PIN));
	}
	return;
}





